import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:moose_app/ui/values/values.dart';

const DEFAULT_AVATAR_IMAGE =
    "https://gitee.com/shizidada/moose-resource/raw/master/avatar/avatar-girl.jpeg";

class ATHUserAvatar extends StatelessWidget {
  final double size;

  final double borderWidth;

  final String avatarPath;

  ATHUserAvatar(
      {this.size, this.borderWidth, this.avatarPath = DEFAULT_AVATAR_IMAGE});

  @override
  Widget build(BuildContext context) {
    double width = size != null ? size : kSize120;
    double height = size != null ? size : kSize120;
    bool isLocal = avatarPath.contains("assets");
    return Container(
      decoration: BoxDecoration(
          border: Border.all(
              color: Colors.white,
              width: borderWidth != null ? borderWidth : kSize2),
          borderRadius: BorderRadius.all(
              Radius.circular(size != null ? size + kSize10 / 2 : kSize60))),
      child: ClipOval(
        child: isLocal
            ? Image.asset(avatarPath,
                width: width, height: height, fit: BoxFit.cover)
            : CachedNetworkImage(
                imageUrl: avatarPath,
                width: width,
                height: height,
                fit: BoxFit.cover),
      ),
    );
  }
}
